/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.api;

import java.util.concurrent.TimeUnit;

/**
 * Lock 对象的异步接口
 * RLockAsync的返回值都是RFuture，是Redisson执行异步实现的核心逻辑，也是Netty发挥的主要阵地
 */
public interface RLockAsync {

    /**
     * 异步强制解锁
     */
    RFuture<Boolean> forceUnlockAsync();

    /**
     * 异步解锁
     */
    RFuture<Void> unlockAsync();

    /**
     * 异步解锁，如果锁未被指定的线程锁定，则抛出此异常threadId
     */
    RFuture<Void> unlockAsync(long threadId);

    /**
     * 异步尝试获取锁
     */
    RFuture<Boolean> tryLockAsync();

    /**
     * 获取锁，必要时要等待，直到锁可用
     */
    RFuture<Void> lockAsync();

    /**
     * 通过定义的线程获取锁threadId。如有必要，等待直到锁可用
     */
    RFuture<Void> lockAsync(long threadId);

    /**
     * 定义锁超时时间，如果超过lesseTime超时时间，就自动把锁释放掉
     */
    RFuture<Void> lockAsync(long leaseTime, TimeUnit unit);

    RFuture<Void> lockAsync(long leaseTime, TimeUnit unit, long threadId);

    /**
     * 尝试通过指定的线程获取锁threadId。
     */
    RFuture<Boolean> tryLockAsync(long threadId);

    /**
     * 尝试获取锁。等待定义waitTime（如有必要），直到锁可用。
     */
    RFuture<Boolean> tryLockAsync(long waitTime, TimeUnit unit);


    RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit);

    /**
     * 设置获取锁定的时间间隔 waitTime，如果超过等待时间，放弃锁定。
     * 如果锁定后，设置锁超时时间leaseTime，在这段时间后锁会自动释放
     */
    RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId);

    /**
     * 当前线程对锁持有次数
     */
    RFuture<Integer> getHoldCountAsync();

    /**
     * 检查锁是否被线程锁定
     */
    RFuture<Boolean> isLockedAsync();

    /**
     * 锁的剩余生存时间
     */
    RFuture<Long> remainTimeToLiveAsync();

}
